<template>
  <van-field v-model="item.value" :class="item.class" :type="item.colType" :border="true" :maxlength="item.colWidth"
    :placeholder="placeholder" :disabled="item.disabled" :required="item.disabled ? false : item.required" :data-rule="item.key" :error-message="errMsg" :rules="item.validate">
    <template #label>
      <span class="custom-title">{{ label }}
        <van-icon v-if="help" name="question" @click="showHelp" />
      </span>
    </template>
  </van-field>
</template>

<script>
import EleBase from './EleBase'

export default {
  name: 'EleText',
  extends: EleBase,
  props: {
    item: {
      type: Object, // 类型
      default: null // 默认值
    }
  },
  data() {
    return {
      inputModel: ''
    }
  },
  computed: {
    errMsg() {
      let str = ''
      if (this.item.required) {
        if (this.item.undermsg === '') {
          str = '请选择' + this.item.label
        } else {
          str = this.item.undermsg
        }
      }
      return str
    },
    placeholder() {
      let str = ''
      if (this.item.placeholder) {
        str = this.item.placeholder
      } else if (this.item.label) {
        str = '请输入' + this.item.label
      }
      return str
    }
  },
  mounted () {
  },
  methods: {
    onChange() {
      this.$emit('onChange', this.item)
    },
    changeRequired(key, value) {
      debugger
      this.$emit('onChangeOtherRequired', { 'key': key, 'value': value })
    }
  }
}
</script>
